define(function(require,exports,module){
	


	//判断是否已认证或开通第三方接口
	$.ajax({
		url:"/member/recharge/checkNewRecharge.html?randomTime=" + (new Date()).getTime(),
		type:"get",
		dataType:"json",
		success:function(data){
			var urlt="/member/security/setting.html";
			if(data.msg=="请先升级密码,目前密码不安全！"){
				urlt="/member/security/setting.html?m=modifyPwd";
			 }
			if(!data.result){
				require.async(['/plugins/layer-v1.8.4/skin/layer.css','/plugins/layer-v1.8.4/layer.min'],function(){
					//构造确认框DOM
					$.layer({
						type: 1,
						closeBtn: false,
		                title: "&nbsp;",
						area: ['450px', '190px'],
						border: [1, 1, '#cecfd0'],
						page: {
						    html: '<div class="tipsWrap w450"><div class="tipsTxt"><i class="iconfont tipIco">&#xe63c;</i><span>'+data.msg+'</span></div><div class="tipsBtnBar"><a href="'+urlt+'" class="okBtn">确定</a></div></div>'
						}
					});
			});
			}
		}
	})

	//TAB切换
	require.async('common1',function(){
		$(".user_right_border").tabChange({
			isClick:true,
            isHover:false,
			childLi:".recharge_list li",//tab选项卡
			childContent:".recharge_content",//tab内容
			hoverClassName:"active",//选中当前选项卡的样式
			callBack:false
		});
	});

	$(".recharge_list  li").on("click",function(){
		var statusVal =$(this).find("span").attr("data-value");
		if(statusVal==3)//线下充值
		{
			$('.paymentStatus').val(2);
			if($("input[name='pay']").attr('disabled')=='disabled'){
				$("input[name='pay']").attr("disabled",false);
			}
			$("#J_reCharge").attr("action","/member/recharge/doOfflineRecharge.html");
			$("#J_reCharge").removeAttr("onsubmit");
			var newCashBtn = '<input type="button" name="name" class="cashBtn" value="确认提交" onClick="return reCharge();"/>';
			$(".paymentStatus").prev().remove();
			$(".paymentStatus").before(newCashBtn);

		}
		else if(statusVal==2){
			if($("input[name='pay']").attr('disabled')=='disabled'){
				$("input[name='pay']").attr("disabled",false);
			}
			$('.paymentStatus').val(1);
			$("#J_reCharge").attr("action","/member/recharge/doRecharge.html");
			$("#J_reCharge").attr("onsubmit","return reCharge();");
			var newCashBtn1 = '<input type="submit" name="name" class="cashBtn" value="确认提交"/>';
			$(".paymentStatus").prev().remove();
			$(".paymentStatus").before(newCashBtn1);
		}//线上充值
		else{
			$('.paymentStatus').val(1);
			$("input[name='pay']").attr('disabled','disabled');
			$("#J_reCharge").attr("action","/member/recharge/doRecharge.html");
			$("#J_reCharge").attr("onsubmit","return reCharge();");
			var newCashBtn1 = '<input type="submit" name="name" class="cashBtn" value="确认提交"/>';
			$(".paymentStatus").prev().remove();
			$(".paymentStatus").before(newCashBtn1);
		}
	})


    	//金额校验
    	var flag;//充值标记
    	function validateMoney(){
    		var moneyVal = $('input[name="money"]').val();
    		if(moneyVal == "")
    		{
    			$('input[name="money"]').focus();
    			$(".money-error").html("请输入充值金额");
    			flag = false;
    		}
    		else if(parseFloat(moneyVal) < 100)
    		{
    			$('input[name="money"]').focus();
    			$(".money-error").html("充值金额不能低于100元");
    			flag = false;
    		}
    		else
    		{
    			$(".money-error").html("");
    			flag = true;
    		}
    	}
    	$('input[name="money"]').on("keyup",function(){
    		validateMoney();
    	});
    	//提交验证
    	function reCharge(){

    		validateMoney();

    		if(flag)
    		{
    			require.async(['/plugins/layer-v1.8.4/skin/layer.css','/plugins/layer-v1.8.4/layer.min'],function(){
					var val=$('.paymentStatus').val();
					//线下转账
					if(val==2)
					{

					   require.async('jquery.form',function(){
						   $("form").ajaxSubmit({
							   dataType:'json',
							   success:function(data){
								if(data.result==true){
				        					$.layer({
										    type: 1,
										    closeBtn: [0,true],
							                title: "&nbsp;",
										    area: ['384px', '186px'],
										    border: [1, 1, '#cecfd0'],
										    time:3,
										    page: {
										        html: '<div class="tipsWrap w384"><div class="tipsTxt"><i class="iconfont okIco">&#xe63d;</i><span>充值申请提交成功，请耐心等待审核！</span></div><div class="tipsBtnBar"><a href="javascript:;" class="okBtn">确定</a></div></div>'
										    },
										    close: function(index){
										    	window.location.reload();
										    },
										    end: function(){
										    	window.location.reload();
										    },
											    success: function(layero){
											    	var time =3;
											    	function closeTime () {
														time--;
														$(".tipsMsg").html(time+"秒后窗口自动关闭");
				    								}
											    	setInterval(function(){
														closeTime();
													}, 1000);
											    }
									});
									$(".okBtn").click(function(){
										window.location.href = "/member/recharge/log.html";
									});
									$(".cancleBtn").click(function(){
										window.location.reload();
									});
							        	}
							        	else
							        	{
						        			$.layer({
											    type: 1,
											    closeBtn: [0,true],
								                title: "&nbsp;",
											    area: ['384px', '186px'],
											    border: [1, 1, '#cecfd0'],
											    page: {
											        html: '<div class="tipsWrap w384"><div class="tipsTxt"><i class="iconfont errIco">&#xe63e;</i><span>'+data.msg+'</span></div><div class="tipsBtnBar"><a href="javascript:;" class="okBtn failBtn">确定</a></div></div>'
											    },
											    close: function(index){
											    	layer.closeAll();
											    	window.location.reload();
											    	$(".valicode_img").each(function(){
													$(this).attr("src",'/validimg.html?t=' + Math.random());
									        			})
											    }
											});
											$(".failBtn").click(function(){
												layer.closeAll();
												$(".valicode_img").each(function(){
													$(this).attr("src",'/validimg.html?t=' + Math.random());
								        				})
											});
							        	}
							}
						   })
					   })
					}
					else if(val==1)//网银充值
					{
						//$.layer({
						//	type: 1,
						//	closeBtn: [0,true],
						//	title: "&nbsp;",
						//	area: ['460px', '194px'],
						//	border: [1, 1, '#cecfd0'],
						//	page: {
						//	   html: '<div class="tipsWrap"><dl><dt>充值完成前，请不要关闭本窗口;</dt><dd>充值完成后，请根据您的充值结果点击下面按钮。</dd></dl><div class="tipsBtnBar"><a href="javascript:;" class="okBtn">充值成功</a><a href="javascript:;" class="cancleBtn">充值失败</a></div></div>'
						//	},
						//	end:function(){
						//		window.location.reload();
						//	}
						//});
						//$(".okBtn").click(function(){
						//	window.location.href = "/member/recharge/log.html";
						//});
						//$(".cancleBtn").click(function(){
						//	layer.closeAll();
						//});
					}
					else//网银直联
					{
						//$.layer({
						//	type: 1,
						//	closeBtn: [0,true],
						//	title: "&nbsp;",
						//	area: ['460px', '194px'],
						//	border: [1, 1, '#cecfd0'],
						//	page: {
						//	   html: '<div class="tipsWrap"><dl><dt>充值完成前，请不要关闭本窗口;</dt><dd>充值完成后，请根据您的充值结果点击下面按钮。</dd></dl><div class="tipsBtnBar"><a href="javascript:;" class="okBtn">充值成功</a><a href="javascript:;" class="cancleBtn">充值失败</a></div></div>'
						//	},
						//	end:function(){
						//		window.location.reload();
						//	}
						//});
						//$(".okBtn").click(function(){
						//	window.location.href = "/member/recharge/log.html";
						//});
						//$(".cancleBtn").click(function(){
						//	layer.closeAll();
						//	$(".valicode_img").each(function(){
						//		$(this).attr("src",'/validimg.html?t=' + Math.random());
						//	})
						//});
					}

			});
			return true;
    		}
    		else
    		{
    			return false;
    		}
    	}

    	exports.reCharge = reCharge;

	function show_recharge(){
		$(".J_valicode_img").each(function(){
			$(this).attr("src",'/validimg.html?t=' + Math.random());
		})
		jQuery( "#modal_dialog" ).dialog({ autoOpen: false , modal: true ,height: 160,width:360 });
		jQuery( "#modal_dialog" ).dialog( "open" );
	}

	//展开更多银行
	if($('.bank_list>li').length>5)
	{
	    var $bank = $('.bank_list li:gt(3):not(:last)');
	    $bank.hide();
		$('.bank_list').append('<li class="otherBank show">请选择其他银行<i class="iconfont">&#xe650;</i></li>');
		$('.otherBank').on('click',function(){
			$bank.show();
			$(this).hide();
		})
    }else{
    	$('.otherBank').remove();
    }

    //点击隐藏表格
    $('.btn_hide').on('click',function(){
    	$('.user_cash_list').hide();
    	$('.recharge_list').css("border","none");
    	$('.user_cash_form .cashBtn').css("margin-top","0px")
    })
    $('.active2').on('click',function(){
    	$('.user_cash_list').show();
    	$('.recharge_list').css("border-bottom","solid 1px #e6e6e6");
        $('.user_cash_form .cashBtn').css("margin-top","30px")
    })

	//表格单双行变色
	$('.user_cash_list tr:gt(0):even').css("background","#e1e4e9");
	$('.user_cash_list tr:gt(0):odd').css("background","#fafbfc");
	$('.user_cash_list tr td:last-child').addClass('font_size');

	//选中单选按钮
	$('._radioCheck li').on("click",function(){
		if($(this).find('input:radio[type=radio]'))
		{
			$(this).find('input:radio[type=radio]').prop("checked",true);
		}
	})

	$('.bank_list li').on("click",function(){
		if(!$(this).hasClass("otherBank"))
		{
			$(this).addClass("active").siblings().removeClass("active");
		}
	});
	//默认选中第一个
	$(".bank_list li:first").addClass("active");
	$(".bank_list li:first input:radio[type=radio]").prop("checked",true);


	//计算充值后可用余额
	$('input[name="money"]').keyup(function(){
		var rechargeMoney = $(this).val();
		if(rechargeMoney == "")
		{
			rechargeMoney	 = 0;
		}
		else
		{
			rechargeMoney = parseFloat(rechargeMoney);
		}
		var remainMoney = parseFloat($("#remainMoney").attr("value"));

		var rechargeSuccessMoney = rechargeMoney +  remainMoney;
		if(rechargeSuccessMoney == 0)
		{
			rechargeSuccessMoney = rechargeSuccessMoney + ".00";
		}
		else
		{
			var n = 2;
			rechargeSuccessMoney = parseFloat((rechargeSuccessMoney + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
			var l = rechargeSuccessMoney.split(".")[0].split("").reverse(), r = rechargeSuccessMoney.split(".")[1];
			var t = "";
			for (var i = 0; i < l.length; i++) {
			t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
			}
			rechargeSuccessMoney = t.split("").reverse().join("") + "." + r;
		}
		$("#rechargeSuccessMoney").html(rechargeSuccessMoney);
	})

});
